<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.getFiles.php');

if (reqVar('azione')=='elimina') {
	$msgPag .= azioneElimina();
}

$sql_sel = "SELECT m.cod_modulo, m.descr as m_descr "
		.", p.id_modulo, p.cod_pagina, p.descr AS p_descr "
		.", c.* "
		.", ra.cod_regola AS reg_acm "
		.", rt.cod_regola AS reg_tra "
		." FROM wfm_comandi c "
		." LEFT JOIN wfm_pagine p ON p.id_pagina = c.id_pagina " 
		." LEFT JOIN wfm_moduli m ON p.id_modulo = m.id_modulo "
		." LEFT JOIN wfm_regole ra ON ra.id_regola = c.id_regola_acm "
		." LEFT JOIN wfm_regole rt ON rt.id_regola = c.id_regola_tra "
		." WHERE c.id_comando = ".reqVarInt('id');
$objDB->query($sql_sel,'selRec');
if(!$aRow = $objDB->fetch('selRec')) {
	backOnErr("id. errato");
}
reqDef('cod_comando',$aRow['cod_comando']);
reqDef('descr',$aRow['descr']);
reqDef('id_regola_acm',$aRow['id_regola_acm']);
reqDef('stato_fin',$aRow['stato_fin']);
reqDef('id_pagina_fin',$aRow['id_pagina_fin']);
reqDef('id_modulo_tra',$aRow['id_modulo_tra']);
reqDef('stato_tra',$aRow['stato_tra']);
reqDef('id_pagina_tra',$aRow['id_pagina_tra']);
reqDef('id_regola_tra',$aRow['id_regola_tra']);
reqDef('nota',$aRow['nota']);
reqDef('idm',$aRow['id_modulo']);
reqDef('idp',$aRow['id_pagina']);

$aCamForm = array();
require("_inc/const.campiCmd.php");

$sCmdR = "";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:confElim();\" >elimina</a>";
$sCmdR .= "&nbsp;&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class=\"cmd1\" href=\"cmdMod.php?id=".reqVarUE('id')."&$sXSNQS"."\" >modifica</a>";
$sCmdR .= cmdTorna('torna');

$sHtmlMod = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>\n";
$sHtmlMod .= getHtmlRigaRif();
$sHtmlMod .= "<tr>\n";
$sHtmlMod .= "<td class='lab1' colspan='3'>Modulo</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='3'>".$aRow['cod_modulo']."</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='14'>".$aRow['m_descr']."</td>\n";
$sHtmlMod .= "</tr>\n";
$sHtmlMod .= "<tr>\n";
$sHtmlMod .= "<td class='lab1' colspan='3'>Pagina</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='3'>".$aRow['cod_pagina']."</td>\n";
$sHtmlMod .= "<td class='txt1' colspan='14'>".$aRow['p_descr']."</td>\n";
$sHtmlMod .= "</tr>\n";
$sHtmlMod .= "</table>";

$aOpz['sottotit'] = $sHtmlMod;

testaHtml('Gestione work-flow','Visualizza comando pagina',$msgPag,'wfma',$aOpz);
?>
<script type="text/javascript">
<!--
function confElim() {
	if (confirm("Confermi l'eliminazione ?")) {
		document.location.href = "pagView.php?<?="id=".reqVarInt('id')."&azione=elimina&$sXSNQS"?>";
	} 
}
//-->
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
			<? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Comando</td>
   </tr>
<?
if (reqVar('id_pagina_fin')) $aVarExt['hrefPagFin'] = "pagView.php?id=".reqVar('id_pagina_fin')."&xsn=".XSN;
echo getHtmlCampiForm($aCamForm,'vis',$aVarExt);
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
			<? echo $sCmdR; ?>
      </td>
   </tr>
</table>
<?
codaHtml();
exit();

function azioneElimina() {
	global $objDB;
	$msg = "";

		if ($msg != "") return $msg;
	
	$sSql = "SELECT cod_comando FROM wfm_comandi WHERE id_comando = ".reqVarInt('id');
	$objDB->exec($sSql);
	$aX = $objDB->fetch();
	
	$sSql = "DELETE FROM wfm_comandi WHERE id_comando = ".reqVarInt('id');
	$objDB->exec($sSql);
	header("location: ".urlTorna("VComando '".$aX['cod_comando']."' eliminato"));
	exit;
}